<html>
<head>
<h1>Create New Transaction</h1>
</head>

<body>
<form action="addtransaction.php" method="GET">
If inputting a debit transaction to pay for balance within account, use a negative number for the amount charged.<br/>
If transaction is a credit transaction to add to balance of account, use a positive number for the amount charged<br/><br/>

Transaction ID: 	<input type='text' name = 'TransactionID' /> <br/>
Account ID: 		<input type='text' name = 'AccountID' /> <br/>
Amount charge: 		<input type='text' name = 'Charge' /> <br/>
Date of Charge: 	<input type='date' name = 'Date_Charge' /> <br/>
Description of charge: 	<input type='text' name = 'Description' /> <br/>

<input type='submit' name = 'create' value='Create'/>
</form>
</body>
<?php
	require "configcmd.php";
	error_reporting(0);
	$Charge = $_GET['Charge'];
	$TransactionID = $_GET['TransactionID'];
	$Date_Charge = $_GET['Date_Charge'];
	$AccountID = $_GET['AccountID'];
	$Description = $_GET['Description'];
	$con = mysql_connect("localhost",$db_user ,$db_pass);

	if (!$con){
		die('Could not connect: ' . mysql_error());
    }

	mysql_select_db($db_name, $con);


	/*$check_Balance="SELECT Balance FROM  `accounts` WHERE  `ID` ='$AccountID';";
	$check_limit="SELECT Bal_limit FROM  `accounts` WHERE  `ID` ='$AccountID';";
	mysql_query($check_Balance);
	mysql_query($check_limit);

	if ($check_limit < ($check_Balance+$Charge)){

	die('Transaction exceeds credit limits: ' . mysql_error());

	}else{*/

	$sql_add = "Update accounts Set Balance=(Balance+'$Charge') Where ID='$AccountID' ;";

	$sql_add1 = "INSERT INTO transactions (Date_Charge, Description,Charge,TransactionID, AccountID) VALUES ('$Date_Charge','$Description','$Charge', '$TransactionID', '$AccountID');";

	mysql_query($sql_add);	
	mysql_query($sql_add1);
	//}

	mysql_close($con);
?>
<br />
<a href="main.php">Home</a>
</html>
